from app.finance.account_flow.model import AccountFlow as AccountFlowTable
from common.mixins import DictMixin
from exts import db
from common import constant


class Account:
    def __init__(self, account_id=None, user_id=None):
        self.id = account_id
        self.user_id = user_id

    def create_flow_by_order(self, order_type, order_id, **kwargs):
        """"""
        aft = DictMixin.from_dict(AccountFlowTable, kwargs)
        aft.creator_id = self.user_id
        aft.account_id = self.id
        aft.transaction_type = constant.TransactionType(order_type)
        aft.order_id = order_id
        db.session.add(aft)

    def remove_flow_by_order(self, order_id):
        aft_query = AccountFlowTable.query.filter_by(order_id=order_id, account_id=self.id)
        db.session.delete(aft_query)

# order_type, order_id, income, should_income, payment, should_payment
